package com.test.selenium.util;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;

import junit.framework.TestCase;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class UTiLogin extends TestCase {
	public static String url;
	public static String username;
	public static String password;
		
	public static void login(WebDriver driver, WebDriverWait wait) throws IOException {
		FileInputStream loginFile;
		loginFile = new FileInputStream(new File("..\\selenium\\src\\Properties\\login.xls"));
		HSSFWorkbook workbook = new HSSFWorkbook(loginFile);
		HSSFSheet sheetQCFRA = workbook.getSheetAt(0);

		Row row = sheetQCFRA.getRow(1);
		url = row.getCell(0).getStringCellValue().trim();
		username = row.getCell(1).getStringCellValue().trim();
		password = row.getCell(2).getStringCellValue().trim();
		
		driver.get(url);
		wait.until(ExpectedConditions.presenceOfElementLocated(By.id("user[username]"))).sendKeys(username);
        driver.findElement(By.id("user[password]")).sendKeys(password);
        driver.findElement(By.className("ui-button-text")).click();
//        String environmentName = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("envName"))).getText();
//        assertTrue(environmentName.equals("QC-FRA"));
	}
}
